<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>运费收入缴费单</title>
<base href="<%=basePath%>">
<script type="text/javascript"
	src="plugins/websocketInstantMsg/ext4/ext-all-debug.js"></script>
<script type="text/javascript" src="static/js/jquery-1.7.2.js"></script>
<script type="text/javascript"
	src="plugins/websocketInstantMsg/ext4/locale/ext-lang-zh_CN.js"></script>
<link rel="stylesheet"
	href="plugins/websocketInstantMsg/ext4/resources/css/ext-all.css" />
</head>
<body>
<div id="div1" style="height:359px"></div>
<div id="aa"></div>
<div id="bb"></div>
</body>
<script type="text/javascript">
Ext.onReady(function () {
	Ext.QuickTips.init();
    var store = Ext.create('Ext.data.ArrayStore', {
        fields:  [ {name:'id'}, {name:'receivableId'},{name:'receivables_invoice_code'},{name:'invoice_bill_code'},{name:'usd'},{name:'rmb'},  
            	 {name:'deductible_invoice_code'},{name: 'deductible_bill_code'},{name:'decuctible_usd'},{name:'decuctible_rmb'}, {name:'auditer'}
                  ],
        pageSize: 20,  //页容量5条数据
        //是否在服务端排序 （true的话，在客户端就不能排序）
        remoteSort: false,
        remoteFilter: true,
        proxy: {
            type: 'ajax',
            url: '<%=basePath%>freight/xian',
            reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
                type: 'json', //返回数据类型为json格式
                root: 'result.list',  //数据
                totalProperty: 'result.total' //数据总条数
            }
        },
        sorters: [{
			property: 'ordeId',
			direction: 'desc'
		}],
        autoLoad: true  //即时加载数据
    }); 
    //部门
    var store5 = Ext.create('Ext.data.Store', {
        fields: ["DEPARTMENT_ID","DEPARTMENT_NAME"],
        remoteSort: false,
        remoteFilter: true,
        proxy: {
            type: 'ajax',
            url: '<%=basePath%>freight/bumen',
            reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
                type: 'json', //返回数据类型为json格式
                root: 'rows5',  //数据
                totalProperty: 'total5' //数据总条数
            }
        },
        sorters: [{
			property: 'ordeId',
			direction: 'desc'
		}],
        autoLoad: true  //即时加载数据
    });
    //业务类型
    var store6 = Ext.create('Ext.data.Store', {
    	fields: ['id', 'name'],
    	data : [
    	        {"id":"", "name":"选择业务类型"},
    			{"id":"1", "name":"船舶"},
    			{"id":"2", "name":"运输"},
    			{"id":"3", "name":"拖车"},
    			{"id":"4", "name":"其他"},

    		]
    });
  //收入发票号
    var store1 = Ext.create('Ext.data.Store', {
        fields: ["id","code"],
        remoteSort: false,
        remoteFilter: true,
        proxy: {
            type: 'ajax',
            url: '<%=basePath%>freight/list',
            reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
                type: 'json', //返回数据类型为json格式
                root: 'rows',  //数据
                totalProperty: 'total' //数据总条数
            }
        },
        sorters: [{
			property: 'ordeId',
			direction: 'desc'
		}],
        autoLoad: true  //即时加载数据
    });

    //抵扣发票号
    var store2 = Ext.create('Ext.data.Store', {
        fields: ["id","code"],
        remoteSort: false,
        remoteFilter: true,
        proxy: {
            type: 'ajax',
            url: '<%=basePath%>freight/list2',
            reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
                type: 'json', //返回数据类型为json格式
                root: 'rows2',  //数据
                totalProperty: 'total2' //数据总条数
            }
        },
        sorters: [{
			property: 'ordeId',
			direction: 'desc'
		}],
        autoLoad: true  //即时加载数据
    });
    //收入业务编号
    var store3 = Ext.create('Ext.data.Store', {
        fields: ["ID","BILL_CODE"],
        remoteSort: false,
        remoteFilter: true,
        proxy: {
            type: 'ajax',
            url: '<%=basePath%>freight/list3',
            reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
                type: 'json', //返回数据类型为json格式
                root: 'rows3',  //数据
                totalProperty: 'total3' //数据总条数
            }
        },
        sorters: [{
			property: 'ordeId',
			direction: 'desc'
		}],
        autoLoad: true  //即时加载数据
    });
    
    //抵扣业务编号
    var store4 = Ext.create('Ext.data.Store', {
    	 fields:["ID","BILL_CODE"],
        remoteSort: false,
        remoteFilter: true,
        proxy: {
            type: 'ajax',
            url: '<%=basePath%>freight/list4',
            reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
                type: 'json', //返回数据类型为json格式
                root: 'rows4',  //数据
                totalProperty: 'total4' //数据总条数
            }
        },
        sorters: [{
			property: 'ordeId',
			direction: 'desc'
		}],
        autoLoad: true  //即时加载数据
    });
   
    var rowEditing = Ext.create('Ext.grid.plugin.CellEditing', {
    	clicksToEdit:2 //设置单击单元格编辑  
        //autoCancel: false
    });

//新建的列表
    var grid = Ext.create('Ext.grid.Panel',{
    renderTo: "aa",
    title: '运费收入新增',
    id:'grid',
    store: store,
    height: 280,
    width:"100%",
    features: [{  
        ftype: 'summary'  
    }], 
    // selModel:Ext.create('Ext.selection.CheckboxModel',{mode:"SIMPLE"}), //复选框
      selModel: { selType: 'checkboxmodel' },//单选框
    columns: [                    
                  { text: 'id', dataIndex: 'id',  maxWidth: 160, hidden:true},
                  { text: '收入发票号',   dataIndex: 'receivables_invoice_code',maxWidth: 160,
                	  
                      editor: {
      			        xtype: 'combo',
      			        typeAhead: true,
      			        triggerAction: 'all',
      			        id:'a',
      			        name:'receivables_invoice_code',
      			        selectOnTab: true,
      			        lazyRender: true,
      			        forceSelection: true,
      			        emptyText:'--请选择--',
      			        editable: false,
      			     // allowBlank: false,
      			       // valueField:'amount',
      			        store: store1,
      			        //displayField:'code',
      			        valueField: 'code',
						displayField:'code',
//       			        listeners: {
      			        	
//       			            'select': function (combo,record,index) {
      			            	
//       			            	 var recei = Ext.getCmp('a').getRawValue();
//       			            	alert(recei)
//       			            	//Ext.getCmp("a").setValue(recei);
      			            	
//       			            }
//       			        }
      			    }},

                
                  { text: '收入业务编号',summaryRenderer: function (value, summaryData, dataIndex) {
						
			        	return Ext.String.format('合计金额：');  
	                },
      			    	dataIndex: 'invoice_bill_code', align: 'left', minWidth: 160,
      			    	
      			    	 editor: {
         			        xtype: 'combo',
         			        typeAhead: true,
         			        triggerAction: 'all',
         			        id:'b',
         			        name:'invoice_bill_code',
         			        selectOnTab: true,
         			        lazyRender: true,
         			        forceSelection: true,
         			        emptyText:'--请选择--',
         			        editable: false,
         			       // valueField:'amount',
         			        store: store3,
         			        //displayField:'code',
         			        valueField: 'BILL_CODE',
   						    displayField:'BILL_CODE',
   						 listeners:{
                       	          blur: function(){
                       	              if(Ext.getCmp('b').getRawValue()==""){
                       		 Ext.MessageBox.alert("提示","收入业务编号不能为空")
                       		              return
                       		              }
                       	          } , 
                         }
                 	  }},            
                
                  { text: '收入美元',dataIndex: 'usd', maxWidth: 120, align: 'left',
                 		  summaryRenderer: function (value, summaryData, dataIndex) {
						var aa= grid.getStore()  
						  var comValue = 0;
						  for(var i=0;i<aa.getCount();i++)
						  {
						     comValue+=parseInt(grid.getStore().data.items[i].data.usd);
						  }
						  Ext.getCmp("heji2").setValue(isNaN(comValue)?0:comValue);
//	 					  alert(comValue);
	                    return isNaN(comValue)?0:comValue
	                },  
                 		  
                	  editor : new Ext.form.TextField({
                		  name:'usd',id:'usd',
                          //allowBlank : false ,
                          listeners:{
                        	          blur: function(){
                        		  var task = new Ext.util.DelayedTask(function(){
									    
									});
									task.delay(500);
                        		  var re =new RegExp(/^^(\-|\+)?\d+(\.\d+)?$$/);//判断输入是否正确
                         		 var q= Ext.getCmp('usd').getValue()
                         		 var a= Ext.getCmp('decuctible_usd').getValue()
                         		 if(q!=""){
                         			 var result=re.test(q);
                             		   if(!result)
                             			      {
                             			        Ext.MessageBox.alert("提示","请正确输入收入美元"); 
                             			Ext.getCmp('usd').setValue(null)
                             			    return 
                             			      }
                           		 
                         		 }
                         		 var num= parseInt(q);
                          		 var num1= parseInt(a);
                          		if(num <num1){
                     				   Ext.MessageBox.alert("提示","抵扣美元大于收入美元请去成本付款审核单新增"); 
                     				  Ext.getCmp('decuctible_usd').setValue(null)
                     			   }
                        	              
                        	          } , 
                          }
                      }),}, 
                  { text: '收入人民币', dataIndex: 'rmb', maxWidth: 120, align: 'left',
                    	  summaryRenderer: function (value, summaryData, dataIndex) {
      						var aa= grid.getStore()  
      						  var comValue = 0;
      						  for(var i=0;i<aa.getCount();i++)
      						  {
      						     comValue+=parseInt(grid.getStore().data.items[i].data.rmb);
      						  }
      						  Ext.getCmp("heji2").setValue(isNaN(comValue)?0:comValue);
//      	 					  alert(comValue);
      	                    return isNaN(comValue)?0:comValue
      	                },  
                    	  editor : new Ext.form.TextField({
                    		  name:'rmb',id:'rmb',
                              //allowBlank : false,
                              listeners:{
                            	          blur: function(){
                            		  var task = new Ext.util.DelayedTask(function(){
  									    
  									});
  									task.delay(500);
                            		  var re =new RegExp(/^^(\-|\+)?\d+(\.\d+)?$$/);
                             		   var q= Ext.getCmp('rmb').getValue()
                             		   var a=Ext.getCmp('decuctible_rmb').getValue()
                             		 if(q!=""){
                             			 var result=re.test(q);
                                 		   if(!result)
                                 			      {
                                 			        Ext.MessageBox.alert("提示","请正确输入收入人民币"); 
                                 			Ext.getCmp('rmb').setValue(null)
                                 			    return 
                                 			      }
                               		 
                             		 }
                             		  var num= parseInt(q);
                               		 var num1= parseInt(a);
                               		if(num < num1){
                          				   Ext.MessageBox.alert("提示","抵扣人民币大于收入人民币请去成本付款审核单新增"); 
                          				  Ext.getCmp('decuctible_usd').setValue(null)
                          			   }
                            	              
                            	          } , 
                              }
                          }),}, 
                  { text: '抵扣发票号', dataIndex: 'deductible_invoice_code', maxWidth: 160, align: 'left',
                        	  editor: {
                			        xtype: 'combo',
                			        typeAhead: true,
                			        triggerAction: 'all',
                			        id:'c',
                			        selectOnTab: true,
                			        lazyRender: true,
                			        forceSelection: true,
                			        emptyText:'--请选择--',
                			        editable: false,
                			       // valueField:'amount',
                			        store: store2,
                			        //displayField:'code',
                			        valueField: 'code',
          						    displayField:'code',   
          						  listeners:{
          	                       	          blur: function(){
          	                       	              if(Ext.getCmp('c').getRawValue()==""){
          	                       	 Ext.MessageBox.alert("提示","抵扣发票号不能为空")
          	                       		              return
          	                       		              }
          	                       	          } , 
          	                         }
                        	  }},
                  { text: '抵扣业务编号', dataIndex: 'deductible_bill_code', maxWidth: 160, align: 'left',
                        		  summaryRenderer: function (value, summaryData, dataIndex) {
              						
              			        	return Ext.String.format('合计金额：');  
              	                },
                        		  editor: {
                  			        xtype: 'combo',
                  			        typeAhead: true,
                  			        triggerAction: 'all',
                  			        id:'d',
                  			        selectOnTab: true,
                  			        lazyRender: true,
                  			        forceSelection: true,
                  			        emptyText:'--请选择--',
                  			        editable: false,
                  			       // valueField:'amount',
                  			        store: store4,
                  			        //displayField:'code',
                  			        valueField: 'BILL_CODE',
            						displayField:'BILL_CODE',    
            						 listeners:{
            	                       	          blur: function(){
            	                       	              if(Ext.getCmp('d').getRawValue()==""){
            	                       		 Ext.MessageBox.alert("提示","抵扣业务编号不能为空")
            	                       		              return
            	                       		              }
            	                       	          } , 
            	                         }
                          	  }},
                  { text: '抵扣美元', dataIndex: 'decuctible_usd', maxWidth: 120, align: 'left',
                          		summaryRenderer: function (value, summaryData, dataIndex) {
              						var aa= grid.getStore()  
              						  var comValue = 0;
              						  for(var i=0;i<aa.getCount();i++)
              						  {
              						     comValue+=parseInt(grid.getStore().data.items[i].data.decuctible_usd);
              						  }
              						  Ext.getCmp("heji2").setValue(isNaN(comValue)?0:comValue);
//              	 					  alert(comValue);
              	                    return isNaN(comValue)?0:comValue
              	                },  
                                	  editor : new Ext.form.TextField({
                                		  id:'decuctible_usd',name:'decuctible_usd',
                                          //allowBlank : false,
                                          listeners:{
                	                       	          blur: function(){
                	                       		  var task = new Ext.util.DelayedTask(function(){
                									    
                									});//计算金额
                									task.delay(500);//计算金额的
                                      var a =new RegExp(/^^(\-|\+)?\d+(\.\d+)?$$/);
                              		 var b= Ext.getCmp('decuctible_usd').getValue()
                              		
                              		  var c= Ext.getCmp('usd').getValue()
                              		
                              		 if(b!=""){
                              			 var result=a.test(b);
                                  		   if(!result)
                                  			      {
                                  			        Ext.MessageBox.alert("提示","请正确输入抵扣美元");
                                  			   Ext.getCmp('decuctible_usd').setValue(null)
                                  			   
                                  			    return 
                                  			      }
                                		 
                              		 }
                              		 var num= parseInt(b);
                              		 var num1= parseInt(c);
                              		if(num >num1){
                         				   Ext.MessageBox.alert("提示","抵扣美元大于收入美元请去成本付款审核单新增"); 
                         				  Ext.getCmp('decuctible_usd').setValue(null)
                         			   }
                             	              
                             	          } , 
                               }
                                      }),}, 
                  { text: '抵扣人民币', dataIndex: 'decuctible_rmb', maxWidth: 120, align: 'left',
                                    	  summaryRenderer: function (value, summaryData, dataIndex) {
                        						var aa= grid.getStore()  
                        						  var comValue = 0;
                        						  for(var i=0;i<aa.getCount();i++)
                        						  {
                        						     comValue+=parseInt(grid.getStore().data.items[i].data.decuctible_rmb);
                        						  }
                        						  Ext.getCmp("heji2").setValue(isNaN(comValue)?0:comValue);
                       	 					  //alert(comValue);
                        	                    return isNaN(comValue)?0:comValue
                        	                },  
                                    	  editor : new Ext.form.TextField({
                                    		  id:'decuctible_rmb',name:'decuctible_rmb',
                                              //allowBlank : false,
                                              listeners:{
                    	                       	          blur: function(){
                    	                    		  var task = new Ext.util.DelayedTask(function(){
                  									    
                  									});//计算金额
                  									task.delay(500);//计算金额的
                                              var a =new RegExp(/^^(\-|\+)?\d+(\.\d+)?$$/);
                                  		 var c= Ext.getCmp('decuctible_rmb').getValue()
                                  		 var rmb= Ext.getCmp('rmb').getValue()
                                  		 if(c!=""){
                                  			 var result=a.test(c);
                                      		   if(!result)
                                      			      {
                                      			        Ext.MessageBox.alert("提示","请正确输入抵扣人民币");
                                      			   Ext.getCmp('decuctible_rmb').setValue(null)
                                      			   
                                      			    return 
                                      			      }
                                    		 
                                  		 }
                                  		 var num= parseInt(c);
                                  		 var num1= parseInt(rmb);
                                  		if(num>num1){
                            				   Ext.MessageBox.alert("提示","抵扣人民币大于收入人民币请去成本付款审核单新增"); 
                            				   Ext.getCmp('decuctible_rmb').setValue(null)
                            			   }
                                	              
                                 	          } , 
                                   }
                                          }),}, 
                                           { text: '审核', dataIndex: 'auditer',maxWidth: 160 ,hidden:true},
                                           { text: 'receivableId', dataIndex: 'receivableId',maxWidth: 160 ,hidden:true},
                                           

                  
                 
               ],
    bbar: [{
        xtype: 'pagingtoolbar',
        store: store,
       
        displayMsg: '显示 {0} - {1} 条，共计 {2} 条',
        emptyMsg: "没有数据",
        beforePageText: "当前页",
        afterPageText: "共{0}页",
        displayInfo: true  ,
//         item:['-', '<font color=clred><div id=currentInfo>保存成功</div></font>']
    	
    }],
	
    plugins:[  rowEditing
//              Ext.create('Ext.grid.plugin.CellEditing',{  
//                  clicksToEdit:2 //设置单击单元格编辑  
//              })  
    ],
     tbar:[
     {text:'新增',iconCls:'a_add',handler:add1},
     {text:'删除',iconCls:'a_add',handler:delet},
  ], 
  listeners: {  
	 // checkchange  itemdblclick
		'cellclick':function(grid,rowIndex,columnIndex,e ){ 
			 var rs=grid.getSelectionModel().getSelection();//获取选中的一行的值		    	
		    	  var auditer=rs[0].data.auditer; //审核状态
		    	if(auditer==1){
		    		 Ext.MessageBox.alert("提示","当前记录审核已通过不能编辑");
		    		return;
		    	}

		    	//var field = Ext.create("Ext.form.field.Text" , {
		    	   // listeners:{
		    	        //blur: function(){
		    	        //  if(rs.data.usd==null || record.data.usd==""){
      		
      			           //  alert("请选择收入业务编号");
		    	       //             }
		    	       // } , 
		    	       // focus: function(){
		    	            //获取焦点
		    	        //}
		    	   // }
		    	//}); 

		  
		}   
		}       
});
   //删除   
   function delet(){
	   var records = grid.getSelectionModel().getSelection();
	   if(records.length==0){
			Ext.Msg.alert("提示","请选中需要删除的记录");return;
			}   
			var id = Ext.getCmp('grid').getSelectionModel().getSelection()[0].get("id");
			//var id = records[0].data.id; //id
			
			//alert(id)
			if(id==""||id==null){
	   var sm = Ext.getCmp('grid').getSelectionModel();
       rowEditing.cancelEdit();
       var store=Ext.getCmp('grid').getStore();
       store.remove(sm.getSelection());
       if (store.getCount() > 0) {
           sm.select(0);
       }
			}else{
				 var auditer=records[0].data.auditer; //审核状态
			    	if(auditer==1){
			    		 Ext.MessageBox.alert("提示","当前记录审核已通过不能删除");
			    		return;
			    	}
			    	var store = Ext.getCmp('grid').getStore();
			    	var store1 = Ext.getCmp('grid1').getStore();
			    	Ext.Ajax.request({
						url:'<%=basePath%>freight/dele',
						params:{
							id : id
						},
						timeout:5000,
						success:function(response){
							Ext.Msg.alert("提示","成功!");
							store.load();
							store1.load();
						},failure:function(response){
							Ext.Msg.alert("提示","请求失败!");
							store.load();
							store1.load();
						}
			
					});	
				
			}
	                   //  var sm = grid.getSelectionModel(); //得到表格的选择模型  
	                              // var cell = grid.getSelectedCell(); //通过选择模型得到选择的单元格    
	                             //  var record = store.getAt(cell[0]);  //得到store对应的Record  
	                             //  stor
   
   }
   
   
//点击新增 自动增加一行
function add1(){
// 	var aa ={  
//             id:'',  
//             receivables_invoice_code:'',
//             invoice_bill_code:'',
//             usd:'',
//             rmb:'',
//             deductible_invoice_code:'',
//             deductible_bill_code:'',
//             decuctible_usd:'',
//             decuctible_rmb:'',	                
//             }
// 	store.insert(0,aa);   
    

	   store.insert(store.getCount(),{
			xh:store.getCount(),id:'',receivables_invoice_code:'',invoice_bill_code:'',usd:'',rmb:'',deductible_invoice_code:'',
			deductible_bill_code:'',decuctible_usd:'',decuctible_rmb:'',
			 
		});

		
  }	
	//保存按钮
	var save = new Ext.Button({
     	text: '保存',
     	width : 40,
		height : 20,
     	 handler: function(){    		 
     		var flag=false;
     		var reciFlag=false;
     		var deciFlag=false;
     		var records = grid.getSelectionModel().getSelection();
    		var array = [];
    		var receipt_app_code = Ext.getCmp('receipt_app_code').getValue();//缴款单号
    		var payment_app_dept=Ext.getCmp("payment_app_dept").getRawValue()//部门
    		var dept_business_type=Ext.getCmp("dept_business_type").getRawValue()//业务类型
    	    var payment_dept = Ext.getCmp('payment_dept').getValue();//付款单位    
			var due_bank = Ext.getCmp('due_bank').getValue();//收款银行
			var remark = Ext.getCmp('remark').getValue();//备注
     		var payment_method = Ext.getCmp('payment_method').getChecked()[0].boxLabel;//收款方式
              grid.getStore().each(function(record){
     		var receivables_invoice_code = record.data.receivables_invoice_code; //收款发票号
      		var invoice_bill_code = record.data.invoice_bill_code; //收款业务编号
      		var usd = record.data.usd; //收入美元
      		var rmb = record.data.rmb; //收入人民币
      		var receivableId = record.data.receivableId
      		var deductible_invoice_code = record.data.deductible_invoice_code; //抵扣发票号
      		var deductible_bill_code = record.data.deductible_bill_code; //抵扣业务号
      		var decuctible_usd = record.data.decuctible_usd; //抵扣美元
      		var decuctible_rmb = record.data.decuctible_rmb; //抵扣人民币
      		if(usd!=""&&rmb!=""){
      			 Ext.MessageBox.alert("提示","收入人民币和收入美元不能同时存在")
       			reciFlag = false
       			 
       		}else{
       			reciFlag=true;
       		}
      		if(decuctible_usd!=""&&decuctible_rmb!=""){
      			 Ext.MessageBox.alert("提示","抵扣人民币和抵扣美元不能同时存在")
       			deciFlag= false
       		}else{
       			deciFlag= true
       		}

        		
      		obj = {
      			id:record.data.id,
      			receipt_app_code : receipt_app_code,//缴款单号
      			payment_app_dept : payment_app_dept,//部门
      			dept_business_type :dept_business_type,//业务类别
      			payment_dept : payment_dept,//付款单位
      			due_bank : due_bank,//收款银行
      			remark : remark,//备注
      			payment_method : payment_method,//收款方式 
     			receivables_invoice_code : receivables_invoice_code,//收款发票号
     			invoice_bill_code : invoice_bill_code, //收款业务编号
     			usd : usd,//收入美元
     			rmb :  rmb,//收入人民币
     			deductible_invoice_code : deductible_invoice_code,//抵扣发票号
     			deductible_bill_code : deductible_bill_code,//抵扣业务号
     			decuctible_usd : decuctible_usd,//抵扣美元
     			decuctible_rmb : decuctible_rmb,//抵扣人民币
     			receivableId:receivableId
     			};
      		
 			array.push(obj);
 			
            	
}); 
     		flag=reciFlag && deciFlag;
     		
     		if(flag){  
             

			var array = JSON.stringify(array);
// 			var store = Ext.getCmp('grid1').getStore();
			var store1 = Ext.getCmp('grid2').getStore();
			Ext.Ajax.request({
				url:'<%=basePath%>freight/save',
				params:{
					array:array,receipt_app_code:receipt_app_code,payment_app_dept:payment_app_dept,dept_business_type:dept_business_type,
					payment_dept:payment_dept,due_bank:due_bank,remark:remark,payment_method:payment_method
				},
				timeout:5000,
				success:function(response){
					Ext.Msg.alert("提示","成功!");
					store.load();
					store1.load();//刷新查询导入列表
				},failure:function(response){
					Ext.Msg.alert("提示","请求失败!");
					store.load();
					store1.load();//刷新查询导入列表
				}
	
			});	
              }

			
//      		var receivables_invoice_code = Ext.getCmp('a').getValue();//收款发票号
//      		alert(receivables_invoice_code)
//      		var dept_business_type = Ext.getCmp('b').getValue();//收款业务编号
//      		alert(dept_business_type)
//      		var usd = Ext.getCmp('usd').getValue();//收款美元
//      		alert(usd)
//      		var rmb = Ext.getCmp('rmb').getValue();//收入人民币
//      		alert(rmb)
//      		var deductible_invoice_code = Ext.getCmp('c').getValue();//抵扣发票号
//      		alert(deductible_invoice_code)
//      		var deductible_bill_code = Ext.getCmp('d').getValue();//抵扣业务编号
//      		alert(deductible_bill_code)
//      		var decuctible_usd = Ext.getCmp('decuctible_usd').getValue();//抵扣美元
//      		alert(decuctible_usd)
//      		var decuctible_rmb = Ext.getCmp('decuctible_rmb').getValue();//抵扣人民币
//      		alert(decuctible_rmb)
     		
     		
     		
		//	});


		}
		});	    
		var c1 = Ext.create('Ext.container.Container', {
			         layout:{ 
				             type:"table", 
				             columns:1
				          },
			
			items : [
                   {
	                xtype : 'textfield',
	                name : 'receipt_app_code',
	                id : 'receipt_app_code',
	                columnWidth :500,
	                padding : '5px',
	                fieldLabel : '缴款单号',
	                anchor: '50%',
	                readOnly: true,
	                emptyText:'请点击查询导入',
	                html:"<a href=''>查看</a>",
	    
                     }, {
          				xtype : "button",
        				// padding : '2px',
        				text : '查询导入',
        				listeners : {
        					'click' : function() {
        						  selWin.show();
        						
        					
        					}
        				}
        				},
        				{
    						xtype : 'combo',
    						name : 'payment_app_dept',
    						id : 'payment_app_dept',
    						columnWidth :500,
    						padding : '5px',
    						fieldLabel : '部门',
    						anchor: '50%',
    						emptyText:'请选部门',
    						store : store5,
    							valueField: 'DEPARTMENT_ID',
    							displayField:'DEPARTMENT_NAME',
    					},
        				{
    						xtype : 'combo',
    						name : 'dept_business_type',
    						id : 'dept_business_type',
    						columnWidth :500,
    						padding : '5px',
    						fieldLabel : '业务类别',
    						anchor: '50%',
    						 emptyText:'请选择业务类别',
    						 store : store6,
    						 valueField: 'id',
    						displayField:'name',
    					},
                     
					{
						xtype : 'textfield',
						name : 'payment_dept',
						id : 'payment_dept',
						columnWidth :500,
						padding : '5px',
						fieldLabel : '付款单位',
						anchor: '50%',
						 emptyText:'请输入付款单位',
					},
					{
						xtype : 'textfield',
						id : 'heji2',
						hidden:true,
						padding : '5px',
					},
					{
						xtype : 'textfield',
						id : 'heji1',
						hidden:true,
					},
					
					{
						xtype : 'textfield',
						name : 'due_bank',
						id : 'due_bank',
						
						padding : '5px',
						fieldLabel : '收款银行',
						emptyText:'请点击收款银行',
					},
					   {
						 xtype: "textarea",
		                    fieldLabel: "备注",
		                    id: "remark",
		                    name:'remark',
		                    emptyText:'请输入备注',
		                    labelSepartor: "：",
		                    labelWidth: 60,
		                    width: 260
					 },					
					]
		});
	
		//查询导入
		 var store11 = Ext.create('Ext.data.Store', {
		        fields:  ["receipt_app_code","payment_app_dept","dept_business_type","payment_dept","due_bank","remark","payment_method",
		                 "usd","rmb","decuctible_usd","dept_business_rmb",],
		        pageSize: 10,  //页容量5条数据
		        //是否在服务端排序 （true的话，在客户端就不能排序）
		        remoteSort: false,
		        remoteFilter: true,
		        proxy: {
		            type: 'ajax',
		            url: '<%=basePath%>freight/aa',
		            reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
		                type: 'json', //返回数据类型为json格式
		                root: 'result.list',  //数据
		                totalProperty: 'result.total' //数据总条数
		            }
		        },
		        sorters: [{
					property: 'ordeId',
					direction: 'desc'
				}],
		        autoLoad: true  //即时加载数据
		    });
		    
		   
		//新建的列表
		    var grid2 = Ext.create('Ext.grid.Panel', {
		    //renderTo: "bb",
		    title: '查询导入列表',
		    id:'grid2',
		    store: store11,
		    height: 300,
		    //width:"100%",
		    //selModel:Ext.create('Ext.selection.CheckboxModel',{mode:"SIMPLE"}),
		    selModel: { selType: 'checkboxmodel' },   //选择框
		    columns: [                    
		                
		                  { text: '缴款单号', dataIndex: 'receipt_app_code',  maxWidth: 140,},
		                  { text: '部门', dataIndex: 'payment_app_dept',  maxWidth: 140,},
		                  { text: '业务类型', dataIndex: 'dept_business_type',  maxWidth: 140,},
		                  { text: '付款单位', dataIndex: 'payment_dept',  maxWidth: 140,},
		                  { text: '收款银行', dataIndex: 'due_bank',  maxWidth: 140,},
		                  { text: '收款方式', dataIndex: 'payment_method',  maxWidth: 140,},		              
		                  { text: '收入美元总和', dataIndex: 'usd', maxWidth: 120, align: 'left', }, 
		                  { text: '收入人民币总和', dataIndex: 'rmb', maxWidth: 150, align: 'left',  }, 		                
		                  { text: '抵扣美元总和', dataIndex: 'decuctible_usd', maxWidth: 80, align: 'left', }, 
		                  { text: '抵扣人民币总和', dataIndex: 'dept_business_rmb', maxWidth: 80, align: 'left',  }, 
		                  { text: '备注', dataIndex: 'remark', maxWidth: 250, align: 'left',  }, 
		               ],
		    bbar: [{
		        xtype: 'pagingtoolbar',
		        store: store11,
		        displayMsg: '显示 {0} - {1} 条，共计 {2} 条',
		        emptyMsg: "没有数据",
		        beforePageText: "当前页",
		        afterPageText: "共{0}页",
		        displayInfo: true                 
		    }],
		    listeners: {  
		    	'cellclick':function(grid,rowIndex,columnIndex,e ){ 
		    		 var rs=grid2.getSelectionModel().getSelection();//获取选中的一行的值

		    	    	 var receipt_app_code=rs[0].data.receipt_app_code; //缴款单号
		    	    	// alert(receipt_app_code)
 		    	    	 Ext.getCmp('receipt_app_code').setValue(receipt_app_code);//给文本框赋值
 		    	    	 
 		    	    	 var payment_app_dept=rs[0].data.payment_app_dept; //部门
 		    	    	 //alert(payment_app_dept)
 		    	    	 if(payment_app_dept==null || payment_app_dept==""){
 		    	    		payment_app_dept=null;
 		    	    	 }
  		    	    	 Ext.getCmp('payment_app_dept').setValue(payment_app_dept);//给文本框赋值
  		    	    	 
  		    	    	 var dept_business_type=rs[0].data.dept_business_type; //业务类型
 		    	    	 //alert(dept_business_type)
  		    	    	 Ext.getCmp('dept_business_type').setValue(dept_business_type);//给文本框赋值
		    	    	
		    	    	 var payment_dept=rs[0].data.payment_dept;//付款单位
		    	    	// alert(payment_dept)
		    	    	 Ext.getCmp('payment_dept').setValue(payment_dept);//给文本框赋值
		    	    	 
		    	    	 var due_bank=rs[0].data.due_bank; //收款银行
		    	    	// alert(due_bank)
		    	    	 Ext.getCmp('due_bank').setValue(due_bank);//给文本框赋值
		    	    	
		    	    	 var remark=rs[0].data.remark;//备注
		    	    	 //alert(remark)
		    	    	 Ext.getCmp('remark').setValue(remark);//给文本框赋值
		    	    	 
		    	    	 var payment_method=rs[0].data.payment_method;//收款方式
		    	    	 //alert(payment_method)
		    	    	 if(payment_method=="现金"){
		    	    		 Ext.getCmp('xianjin').setValue(true);
		    	    	 }if(payment_method=="支票"){
		    	    		 Ext.getCmp('zhipiao').setValue(true);
		    	    	 }if(payment_method=="汇款"){
		    	    		 Ext.getCmp('huikuan').setValue(true);
		    	    	 }if(payment_method=="其他"){
		    	    		 Ext.getCmp('qita').setValue(true);
		    	    	 }
		    	    		 
		    	    	 //Ext.getCmp('remark').setValue(remark);//给文本框赋值
		    	    	 var store = Ext.getCmp('grid').getStore();
		    	    	 store.on('beforeload', function(store, options) {
								var new_params = {
// 										id:id,
										receipt_app_code:receipt_app_code,
									
								};
								Ext.apply(store.proxy.extraParams, new_params);
							});
		    	    	 selWin.close();
							store.load();
		    	    	

		    	}   
		    	}  
		});
		var selForm = Ext.create('Ext.form.Panel', {
		    name: 'selForm',
		    bodyStyle: {
		        background: '#DFE9F6',
		        padding: '5px',
		        border: 0
		    },
		    fieldDefaults: {
		        labelAlign: 'left'
		    },
		    items: [grid2]
		});
		var selWin = Ext.create('Ext.window.Window', {
		    //title: '查询',
		    width: 650,
		    height: 350,
		    modal : true,
		    items: [selForm],
		    //items: [grid2],
		    closeAction: 'hide',
		    closeable: true,
		    iconCls: 'modalWin',
		    buttonAlign: 'center',
// 		    buttons: [
// 		        {text: '查询',handler: function() { formSubmit(); }},
// 		        {text: '清空',handler: function() { selForm.form.reset(); }},
// 		        {text: '关闭', handler: function() { selWin.close(); }}
// 		    ]
		});
		//收款方式
		   var radiogroup = new Ext.form.RadioGroup({
			                    fieldLabel: '收款方式',
			                    width: 430,
			                    id:'payment_method',
			                    name:'payment_method',
			                   items: [{boxLabel: '现金',
			                	       id:'xianjin',
				                      inputValue: "0",
				                      name:"payment_method",
				                    	  checked: true 

				                   }, {
				                        boxLabel: '支票',
				                        inputValue: '1',
				                        id:'zhipiao',
				                        name:'payment_method'
				                    	  
				                   }, {
				                       boxLabel: '汇款',
				                      inputValue: '2',
				                      id:'huikuan',
				                      name:'payment_method'
				                   }, {
				                       boxLabel: '汇票',
					                    inputValue: '3',
					                    id:'huikuan',
					                    	name:'payment_method'
					                   }, {
					                       boxLabel: '其他',
					                       id:'qita',
						                      inputValue: '4',
						                    	name:'payment_method'
						                   }
			                   ]
			
        });
       //获取单选的值
//  var sex = Ext.getCmp('payment_method').getChecked()[0].boxLabel;
// alert(sex)
		
           //把查询的列表放进form中
		var form = Ext.create('Ext.form.Panel', {
			renderTo : 'div1',
			 title: '运费收入录入',
			id:'form',
			frame : true,		
			items : [ c1, radiogroup,save,],

 		});
});




 		//运费收入展示页面
		Ext.onReady(function () {
		 var store10 = Ext.create('Ext.data.Store', {
		        fields:  ["id","payment_dept","due_bank","payment_method","receivables_invoice_code","invoice_bill_code","usd",
		                  "rmb","deductible_invoice_code","deductible_bill_code","decuctible_usd","dept_business_rmb","remark",
		                  "receipt_app_code","payment_app_dept","dept_business_type"],
		        pageSize: 10,  //页容量5条数据
		        //是否在服务端排序 （true的话，在客户端就不能排序）
		        remoteSort: false,
		        remoteFilter: true,
		        proxy: {
		            type: 'ajax',
		            url: '<%=basePath%>freight/display',
		            reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
		                type: 'json', //返回数据类型为json格式
		                root: 'rows10',  //数据
		                totalProperty: 'total10' //数据总条数
		            }
		        },
		        sorters: [{
					property: 'ordeId',
					direction: 'desc'
				}],
		        autoLoad: true  //即时加载数据
		    });
		    
		   
		//新建的列表
// 		    var grid1 = Ext.create('Ext.grid.Panel', {
// 		    renderTo: "bb",
// 		    title: '运费收入显示',
// 		    id:'grid1',
// 		    store: store10,
// 		    height: 400,
// 		    width:"100%",
		    
// 		    selModel:Ext.create('Ext.selection.CheckboxModel',{mode:"SIMPLE"}),
// 		    //selModel: { selType: 'checkboxmodel' },   //选择框
// 		    columns: [                    
// 		                  { text: 'id', dataIndex: 'id',  maxWidth: 80 ,hidden:true, },
// 		                  { text: '缴款单号', dataIndex: 'receipt_app_code',  maxWidth: 140,},
// 		                  { text: '部门', dataIndex: 'payment_app_dept',  maxWidth: 140,},
// 		                  { text: '业务类型', dataIndex: 'dept_business_type',  maxWidth: 140,},
// 		                  { text: '付款单位', dataIndex: 'payment_dept',  maxWidth: 140,},
// 		                  { text: '收款银行', dataIndex: 'due_bank',  maxWidth: 140,},
// 		                  { text: '收款方式', dataIndex: 'payment_method',  maxWidth: 140,},
// 		                  { text: '收入发票号', dataIndex: 'receivables_invoice_code',  maxWidth: 140,},
// 		                  { text: '收入业务编号', dataIndex: 'invoice_bill_code', align: 'left', minWidth: 180, },
// 		                  { text: '收入美元', dataIndex: 'usd', maxWidth: 120, align: 'left', }, 
// 		                  { text: '收入人民币', dataIndex: 'rmb', maxWidth: 150, align: 'left',  }, 
// 		                  { text: '抵扣发票号', dataIndex: 'deductible_invoice_code', maxWidth: 150, align: 'left', }, 
// 		                  { text: '抵扣业务编号', dataIndex: 'deductible_bill_code', maxWidth: 120, align: 'left',  }, 
// 		                  { text: '抵扣美元', dataIndex: 'decuctible_usd', maxWidth: 80, align: 'left', }, 
// 		                  { text: '抵扣人民币', dataIndex: 'dept_business_rmb', maxWidth: 80, align: 'left',  }, 
// 		                  { text: '备注', dataIndex: 'remark', maxWidth: 250, align: 'left',  }, 
// 		               ],
// 		    bbar: [{
// 		        xtype: 'pagingtoolbar',
// 		        store: store10,
// 		        displayMsg: '显示 {0} - {1} 条，共计 {2} 条',
// 		        emptyMsg: "没有数据",
// 		        beforePageText: "当前页",
// 		        afterPageText: "共{0}页",
// 		        displayInfo: true                 
// 		    }],
		  
// 		    tbar:[     
// // 		          {text:'导出',iconCls:'a_edit2',}
// 		          ], 
		     
// 		});

		});





</script>
</html>